#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "lcd_dev.h"
#include "lcd_drv.h"
#include "key.h"

#include <iconv.h>
#include "icons.h"

char *str = "你好吗？";

void utf2gbk(char *str, char *outbuf)
{
    iconv_t cd;
    char *inbuf = str;
    char *outptr = outbuf;
    size_t inbytesleft = strlen(str);
    size_t outbytesleft = 64;
    size_t ret;

    cd = iconv_open("GBK", "UTF-8");
    if (cd == (iconv_t) -1) {
        perror("iconv_open");
        return;
    }

    ret = iconv(cd, &inbuf, &inbytesleft, &outptr, &outbytesleft);
    if (ret == (size_t) -1) {
        perror("iconv");
        iconv_close(cd);
        return;
    }

    iconv_close(cd);
}

void gui_test(void)
{
    int	i;
    int	j;

    lcd_put_pixel(0, 0, LCD_BACK_COLOR);
    lcd_put_pixel(3, 3, LCD_FRONT_COLOR);

    lcd_put_hzk16(0, 0, "你", LCD_DISPLAY_NORMAL);
    lcd_put_ascii16(0, 0, 'A', LCD_BACK_COLOR, LCD_FRONT_COLOR);

    lcd_put_str16(0, 0, "12345678你好吗？", LCD_DISPLAY_NORMAL);
    usleep(500 * 1000);
    lcd_put_str16(0, 1, "12345678吃饭睡觉", LCD_DISPLAY_RESVERSE);
    usleep(500 * 1000);
    lcd_put_str16(0, 2, "12345678吃饭睡觉", LCD_DISPLAY_NORMAL);
    usleep(500 * 1000);
    lcd_put_str16(0, 3, "12345678吃饭睡觉", LCD_DISPLAY_RESVERSE);
    usleep(500 * 1000);
    lcd_put_str16(0, 4, "12345678吃饭睡觉", LCD_DISPLAY_NORMAL);
    getchar();
}

void gui_icon_test(void)
{
    lcd_put_str12(0, 30, "12345678吃饭睡觉", LCD_DISPLAY_NORMAL);
    lcd_put_icon24(24, 0, icon_5g_1, LCD_DISPLAY_NORMAL);
    lcd_put_icon24(48, 0, icon_4g_1, LCD_DISPLAY_NORMAL);
    lcd_put_icon24(72, 0, icon_4g_2, LCD_DISPLAY_NORMAL);
    lcd_put_icon24(96, 0, icon_4g_3, LCD_DISPLAY_NORMAL);
    lcd_put_icon24(120, 0, icon_4g_4, LCD_DISPLAY_NORMAL);

    while (1) {
        for (int i = 0; i < 4; i++) {
            lcd_put_icon24(0,  0, icon_4g[i], LCD_DISPLAY_NORMAL);
            usleep(1000 * 300);
        }
    }
}
